import imapi from '../../../../utils/imapi.js'
var app = getApp()
Component({
  properties: {
    type: {   //1的话是网格显示，0的是横隔
      type: Number,
      value: 0
    },
    liveList: {
      type: Array,
      value: [],
      observer: function (newVal, oldVal) {	  
        if (!oldVal[0]) return;
        for (var i = 0; i < oldVal.length; i++) {
          if(newVal[i] && oldVal[i]){
            if (newVal[i].item_id == oldVal[i].item_id) {
              newVal[i] = oldVal[i]
            }
          }
          
        }
      }
    },
    showTitle: {
      type: Boolean,
      value: true
    },
    showIndex: {
      type: Number,
      value: 0,
      observer: 'listChange'
    },
    zIndex: {
      type: Boolean,
      value: true
    },
    scale: {
      type: Number,
      value: 1,
    },
  },
  data: {
    liveList: [],
    is_test: app.globalData.is_test,

    width: 120,
    height: 41,
    fontSize: 17,
    color: '#FFFFFF',
    backgroundColor: '#6467F0',
    customParams: '',
    live_id: 0,
    is_show_more_visible:false,
  },
  ready() {
	  console.log('传过来的数据');
    console.log(this.data.liveList);
    this.setData({
      is_test: app.globalData.is_test,
      is_show_more_visible:!app.globalData.is_audit,

    })

     
    

    let width = 120
    let height = 41
    let fontSize = 17
    let color = '#FFFFFF'
    let backgroundColor = '#6467F0'
    let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/module/productDetail/productDetail' }))// 开发者在订阅组件上携带自定义参数（如示例中的path和pid参数），后续可以在 App onShow 生命周期的 options 里获取（上限600个字符，超过部分会被截断）
    this.setData({
      width,
      height,
      fontSize,
      color,
      backgroundColor,
      customParams,


    })




  },
  methods: {
    //商品详情
    liveDetail(e) {
      if (this.long_click) {
        this.long_click = false
        return
      }
      var id = e.currentTarget.dataset.id;
      var p = e.currentTarget.dataset.p;
      var index = e.currentTarget.dataset.index;
     
      if (p === 'XP') {
        // 测试成功的第一种方案
        let roomId = id // 填写具体的房间号，可通过下面【获取直播房间列表】 API 获取

        this.setData({
          live_id: roomId
        })

        // let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/module/productDetail/productDetail' })) // 开发者在直播间页面路径上携带自定义参数（如示例中的path和pid参数），后续可以在分享卡片链接和跳转至商详页时获取，详见【获取自定义参数】、【直播间到商详页面携带参数】章节（上限600个字符，超过部分会被截断）
        wx.navigateTo({
          url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${this.data.customParams}`
        })


        // 其中wx2b03c6e691cd7370是直播组件appid不能修改

        /* 这样写目前有白屏
        wx.navigateTo({
            url: '/pages/module/liveDetail/liveDetail?live_id=' + id,
        })
        */
      } else {
        app.globalData.cur_product = this.data.liveList[index]; // cur_product 只用于商品 数据
        wx.navigateTo({
          url: '/pages/module/productDetail/productDetail?id=' + id + '&p=' + p,
        })
      }

    },
    // videoChange(e){
    //   if(!this.videocom1) return;
    //   if(e.currentTarget.id == this.videocom1.id || e.currentTarget.id == this.videocom2.id){
    //     if(e.detail.currentTime>=7){
    //       this.videocom1.seek(0)
    //       this.videocom2.seek(0)
    //       if(!this.videocom3) return;
    //       this.videocom3.seek(0)
    //       this.videocom4.seek(0)
    //     }
    //   }
    // },
    // listChange(e){
    //   var that = this;
    //   this.setData({
    //     zIndex:false
    //   })
    //   var text1 = 'video' + (e * 2 + 0)
    //   this.videocom1 = wx.createVideoContext(text1, that)
    //   this.videocom1.id = text1
    //   var text2 = 'video' + (e * 2 + 1)
    //   this.videocom2 = wx.createVideoContext(text2, that)
    //   this.videocom2.id = text2
    // },
    moreLive() {
      wx.switchTab({
        url: '/pages/tabbar/live/live', //更多就跳转到直播页面
      })
    },
    // calculate(){
    //   var that = this;
    //   const query = wx.createSelectorQuery().in(this);
    //   query.select('#videocom0').boundingClientRect();
    //   query.exec((res) => {
    //     that.triggerEvent('videoInfo', {res: res});
    //   });
    // },
    imgLoad(e) {
      var index = e.currentTarget.dataset.index;
      this.data.liveList[index].imgShow = true;
      this.setData({
        liveList: this.data.liveList
      })
      this.triggerEvent('imgload', { index: index })
    },
    goHot(e) {
      var index = e.currentTarget.dataset.index;
      this.data.liveList[index].is_show_mask = false;
      this.setData({
        liveList: this.data.liveList
      })
      wx.navigateTo({
        url: '/pages/module/hot/hot?q=' + this.data.liveList[index].cid_name,
      })
    },
    showMask(e) {
      this.long_click = true
      var index = e.currentTarget.dataset.index;
      this.data.liveList.forEach(item => {
        item.is_show_mask = false;
      })
      this.data.liveList[index].is_show_mask = true;
      this.setData({
        liveList: this.data.liveList
      })
    },
    hideMask(e) {
      if (this.long_click) {
        this.long_click = false
        return
      }
      var index = e.currentTarget.dataset.index;
      this.data.liveList[index].is_show_mask = false;
      this.setData({
        liveList: this.data.liveList
      })
    }
  },
})